package com.dyz.leetcode._04_bitOperation;

import java.util.HashSet;
import java.util.Set;

public class _137_singleNumber {
    //hash思想
    public int singleNumber(int[] nums) {
        Set<Integer> set1 = new HashSet();
        Set<Integer> set2 = new HashSet();
        for(int num:nums){
            if(set1.contains(num)){
                set1.remove(num);
            }else if(!set2.contains(num)){
                set1.add(num);
            }

            if(set2.contains(num)){
                set2.remove(num);
            }else if(!set1.contains(num)){
                set2.add(num);
            }
        }
        return set1.iterator().next();
    }
    public int singleNumber1(int[] nums) {
        int one = 0;
        int two = 0;
        for(int num:nums){
            one = (one ^ num) & ~two;
            two = (two ^ num) & ~one;

        }
        return one;
    }

    public static void main(String[] args) {
        System.out.println(3 ^ (-3));
    }
}
